package com.hejl.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author Hejl
 * @version 1.0
 * @description
 * @className ChatAiController
 * @date 2025/6/9 11:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/ai")
public class ChatAiController {

    private  final ChatClient chatClient;



    /**
     * @param
     * @return java.lang.String
     * @description 角色预设，使用非流式输出
     * @author Hejl
     * @date 2025/6/9 11:20
     */
    @RequestMapping("/chat01")
    public String chat(@RequestParam(value = "prompt", defaultValue = "你好") String input,@RequestParam(value = "chatId") String chatId) {
        String result = chatClient.prompt().
                ////用户输入的信息
                user(input).
                //调用大模型
                call().
                //获取结果
                content();
        System.out.println(result);
        return result;
    }
    @RequestMapping(value = "/chat",produces = "text/html;charset=UTF-8")
    public Flux<String> chatStream(@RequestParam(value = "prompt", defaultValue = "你好") String prompt,@RequestParam(value = "chatId") String chatId) {
        System.out.println("chatID:"+chatId);
        return chatClient.prompt().user(prompt).stream().content();

    }
}